package cn.weiron.fun.infrastructure.dictionary.repository;

import cn.weiron.fun.infrastructure.dictionary.Dictionary;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 仓储层：字典仓储服务接口MySQL实现
 */
@Repository("dictionaryRepositoryMysql")
public class DictionaryRepositoryMysqlImpl implements DictionaryRepository {
    /**
     * 数据管理服务
     */
    private final DictionaryMysqlRepository mysqlRepository;

    /**
     * 获取全部的字典信息
     * @return
     */
    @Override
    public List<Dictionary> findAll() {
        return mysqlRepository.findAll().stream()
                .map(DictionaryMysqlRepository.Assembler::to)
                .collect(Collectors.toList());
    }

    public DictionaryRepositoryMysqlImpl(
            @Qualifier("dictionaryMysqlRepository") DictionaryMysqlRepository mysqlRepository
    ) {
        this.mysqlRepository = mysqlRepository;
    }
}